<?php
!defined('P_W') && exit('Forbidden');

/**
 *
 * 个人房源数统计服务
 *
 */
class PW_SecondPostService {
	var $_secondpostDB;
	
	function __construct() {
		$this->_secondpostDB = $this->_getSecondpostDB();
	}
	
	function PW_SecondPostService() {
		$this->__construct();
	}
	/**
	 * 获取一个用户的二手房发布数量信息
	 * @param $uid
	 */
	function getSecondPost($uid) {
		global $tdtime;
		static $secondPost = array();
		if($secondPost[$uid]) return $secondPost[$uid];
		$temp = $this->_secondpostDB->get($uid);
		if (!$temp) return array();
		$updateFiled = array();
		if ($temp['lastsaletime']<$tdtime) {
			$updateFiled['todaysalenum'] = $temp['todaysalenum'] = 0;
		}
		if ($temp['lasthiretime']<$tdtime) {
			$updateFiled['todayhirenum'] = $temp['todayhirenum'] = 0;
		}
		if ($updateFiled) {
			$this->_secondpostDB->update($updateFiled,$uid);
		}
		$secondPost[$uid] = $temp;
		return $temp;
	}
	
	/**
	 * 添加或减少salenum的数量
	 * @param $uid
	 * @param $num
	 * @param $isbroker 是否是经纪人
	 */
	function addSaleNum($uid,$num=1,$isbroker=0) {
		$uid = (int) $uid;
		$num = (int) $num;
		$this->_secondpostDB->addSalenum($uid,$num,$isbroker);
	}
	/**
	 * 添加或减少hirenum的数量
	 * @param $uid
	 * @param $num
	 * @param $isbroker 是否是经纪人
	 */
	function addHireNum($uid,$num=1,$isbroker=0) {
		$uid = (int) $uid;
		$num = (int) $num;
		$this->_secondpostDB->addHirenum($uid,$num,$isbroker);
	}
	/**
	 * 获取相关DB
	 * @return PW_House_SecondPostDB
	 */
	function _getSecondpostDB() {
		return House::LoadDB('House_SecondPost');
	}
}